package bstsetcode.linkedliststack;

/**
 * 链表实现栈
 * @author noob
 * @version 1.0
 * @date 2021/3/15 9:31
 */
public class LinkedListStack<E> implements Stack<E>{

    private LinkedList2<E> list;


    public LinkedListStack(){
        list = new LinkedList2<>();
    }


    @Override
    public int getSize() {
        return list.getSize();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public void push(E e) {
        list.addFirst(e);
    }

    @Override
    public E pop() {
        return list.removeFirst();
    }

    @Override
    public E peek() {
        return list.getFirst();
    }


    @Override
    public String toString() {
        StringBuilder res = new StringBuilder();
        res.append("LinkedlistStack: top ");
        res.append(list);
        return  res.toString();
    }
}
